package cn.edu.scau.cmi.chenyuanying.multiton;

import java.net.URL;
import java.util.List;
import java.util.ResourceBundle;

import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.Button;
import javafx.scene.control.TextArea;
import javafx.scene.control.TextField;
import javafx.scene.input.MouseEvent;

public class MultitonController implements Initializable{
	@FXML private Button multiCreateButton;
	@FXML private TextField inputMultiName;
	@FXML private TextArea marshalsLabels;
	
	@Override
	public void initialize(URL location, ResourceBundle resources) {
		// TODO Auto-generated method stub
		
	}
	
	public void createMultiMarshals(ActionEvent e) {
		String name = inputMultiName.getText();
		boolean notFull = Marshal.insert(name);
		StringBuilder sb = new StringBuilder();
		List<Marshal> marshalsList = Marshal.getInstances();  
		for(Marshal s : marshalsList) {
			sb.append(s.toString()+"\n");
		}
		marshalsLabels.setText(sb.toString());
		if(!notFull) marshalsLabels.appendText("You can not create anymore Marshal.");
		
	}
	
	public void clearInputName(MouseEvent e) {
		inputMultiName.setText("");
	}
}
